# from concurrent.futures import ProcessPoolExecutor
# import os
# import time
# import random
#
# def task():
#     print(f'{os.getpid()} is running')
#     time.sleep(random.randint(0,2))
#     return f'{os.getpid()} is finish'
#
# if __name__ == '__main__':
#
#     p = ProcessPoolExecutor(4)
#     obj_l1 = []
#     for i in range(10):
#         obj = p.submit(task,)  # 异步发出.
#         obj_l1.append(obj)
#
#     # time.sleep(3)
#     p.shutdown(wait=True)
#     # 1. 阻止在向进程池投放新任务,
#     # 2. wait = True 十个任务是10,一个任务完成了-1,直至为零.进行下一行.
#     # print(666)
#     for i in obj_l1:
#         print(i.result())
    # 异步回收任务的方式一: 我将所有的任务的结果统一收回.



# 同步发布任务: 我要发布10个任务,先把第一个任务给第一个进程,等到第一个进程完成之后.
# 我在将第二任务给了下一个进程,......

# 异步发布任务: 我直接将10个任务抛给4个进程, 我就继续执行下一行代码了.等结果.




# 同步:

# from concurrent.futures import ProcessPoolExecutor
# import os
# import time
# import random
#
# def task():
#     print(f'{os.getpid()} is running')
#     time.sleep(1)
#     return f'{os.getpid()} is finish'
#
# if __name__ == '__main__':
#
#     p = ProcessPoolExecutor(4)
#
#     for i in range(10):
#         obj = p.submit(task,)  # 异步发出.
#         print(obj.result())

